package com.woniu.humanresource.controller;

import com.woniu.humanresource.entity.JobCategory;
import com.woniu.humanresource.entity.JobLevel;
import com.woniu.humanresource.entity.PageBean;
import com.woniu.humanresource.entity.ResponseText;
import com.woniu.humanresource.exception.GeneralException;
import com.woniu.humanresource.service.JobCategoryService;
import com.woniu.humanresource.service.JobLevelService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class JobLevelController {

    @Resource
    JobLevelService jobLevelService;

    // 删除职位类别





    // 修改职位级别
    @PutMapping("updateJobLv/{position}")
    public ResponseText updateJobLv(@PathVariable("position") String position,
                                    @RequestBody JobLevel jobLevel) {
        ResponseText responseText = null;
        try {
            jobLevelService.updateJobLevel(jobLevel,position);
            responseText = new ResponseText(null, 200, "修改职位级别成功！");
        }catch (Exception e){
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }


    // 添加职位级别
    @PostMapping("insertJoblv")
    public ResponseText insertJoblv(@RequestBody JobLevel jobLevel) {
        ResponseText responseText = null;
        try {
            jobLevel.setJoblvstatus(0);
            jobLevelService.insertJobLevel(jobLevel);
            responseText = new ResponseText(null,200,"添加职位级别成功！");
        }catch (Exception e){
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }


    // 查询所有职位级别
    @GetMapping("getAllJobLevel/{pageIndex}/{pageSize}")
    public ResponseText selectAllJobLevel(@PathVariable("pageIndex") int pageIndex,
                                       @PathVariable("pageSize") int pageSize
                                       ){
        ResponseText<PageBean<JobLevel>> responseText = null;
        try {
            PageBean<JobLevel> allJobLevelpageBean = jobLevelService.getAllJobLevel(pageIndex,pageSize);
            responseText = new ResponseText<>(allJobLevelpageBean,200,"查询到所有职位级别！");
        }catch (Exception e){
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }
    //通过职位级别查询
    @GetMapping("getJobLevelByJoblv/{joblv}/{pageIndex}/{pageSize}")
    public ResponseText selectAllJobLeveByJoblv(@PathVariable("joblv") int joblv,
                                                @PathVariable("pageIndex") int pageIndex,
                                                @PathVariable("pageSize") int pageSize) {
        ResponseText<PageBean<JobLevel>> responseText = null;
        try {
            PageBean<JobLevel> allJobLevelByJoblc = jobLevelService.getAllJobLevelByJoblv(joblv,pageIndex,pageSize);
            responseText = new ResponseText<>(allJobLevelByJoblc,200,"通过职位级别查询！");
        }catch (Exception e){
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }
    //通过职位级别、职位查询
    @GetMapping("getJobLevelByJoblvPosition/{joblv}/{position}")
    public ResponseText selectJobLevelByJoblvPosition(@PathVariable("joblv") int joblv,
                                                      @PathVariable("position") String position) {
        ResponseText<PageBean<JobLevel>> responseText = null;
        try {
            PageBean<JobLevel> jobLevelByJoblvPosition = jobLevelService.getJobLevelByJoblvPosition(joblv,position);
            responseText = new ResponseText<>(jobLevelByJoblvPosition,200,"通过职位级别、职位查询！");
        }catch (Exception e){
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

    //提交删除申请
    @DeleteMapping("deleteJoblvApplyByPosition/{position}")
    public ResponseText deleteJoblvApplyByPosition(@PathVariable("position") String position) {
        ResponseText responseText = null;
        try {
            jobLevelService.deleteApplyByPosition(position);
            responseText = new ResponseText(null,200,"删除职位级别申请提交成功！");
        }catch (Exception e){
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }
    //条件查询
    @PostMapping("getJoblv/{pageIndex}/{pageSize}")
    public ResponseText getJoblv(@PathVariable("pageIndex") int pageIndex,
                                 @PathVariable("pageSize") int pageSize,
                                 @RequestBody JobLevel jobLevel) {
        ResponseText<PageBean<JobLevel>> responseText = null;
        try {
            PageBean<JobLevel> joblvpageBean = jobLevelService.getJoblv(jobLevel,pageIndex,pageSize);
            responseText = new ResponseText(joblvpageBean,200,"条件查询成功！");
        }catch (Exception e){
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }
}
